Fix network corruption with bad processing of UniversalPacket
#76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Few weeks ago I got someone that try my first release of ComputerCraft for BTA. There was a report for this person where my mod did make some
Unexpected network errorbut after further test from my side, I didn't understand which mod was doing this and couldn't reproduce this bug.Today on my personal server with only CC and Halplibe, this bug reoccurred but this time I was able to debug and find a fix.
From the error message it was appearing one of the BTA Packet didn't do it's job and did a partial read, since every packet are kind aligned to the same stream, if one one of them don't read everything, everything is unaligned and now we got packet that try to decode garbage.
For better understanding I did create a build of Halplibe to see exactly what was send and receive from the
UniversalPacketand I found those strange result :Here the server send 5

TurtleBrainClientMessageand you can see the amount of byte the buffer is sending. Here nothing is strange.However on the client, we can clearly see one of those reception don't read the full content of what the server is sending which mean we left junk for other network process

It appear that
dis.read(buffer, 0, length)ordis.read(buffer)don't guaranteed the read of length can be done in one operation since again it appear the stream don't fill with the necessary data in one write.So after some try I found
dis.readFully(buffer, 0, lengthfix everything and now I can't reproduce anymore on my server this error.